var mongoose = require('mongoose');
var homeworkSchema = require('./homeworkschema.model.js')
var Schema = mongoose.Schema;


var HomeworkSchema = new Schema({
    setDate: {
        type: Date,
        default: Date.now
    },
    homeworkName: {
        type: String,
        trim: true
    },
    deadLine: {
        type: Date
    },
    homeworkDetail:{
        type: String,
        trim: true
    },
    department:{
        type: Number
    },
    display: {
        type: Array,
        default: []
    },
    inCharge: {
        type: String,
        trim: true
    },
    staffNum: {
        type: Number
    },
    updateNum: {
        type: Number,
        default: 0
    },
    file: {
        type: String
    }

});

var User = mongoose.model('User');
User.find({},function(err, result){
    if (err) throw err;

    var toBeAdd = {};

    result.forEach(function(user){
        toBeAdd[user.userid] = homeworkSchema;
    })
    HomeworkSchema.add(toBeAdd);

    mongoose.model('Homework', HomeworkSchema);
    console.log('Homework 模型已经建立...');
})



module.exports = HomeworkSchema